using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
// using DG.Tweening;


public class TestFormatTrans : MonoBehaviour
{
    public void test_format_string()
    {
        BdUtils.assert(TranslatorManager.instance, "*** `TranslatorManager.instance`为null?");

        Dictionary<string, object> template_variable_dc = new Dictionary<string, object>();
        string name = TranslatorManager.instance.is_cn ? "博得" : "bode";
        template_variable_dc.Add("name", name);
        template_variable_dc.Add("hp", "90/100");
        template_variable_dc.Add("mp", "150/200");
        template_variable_dc.Add("level", 3);

        string code = "test_format_string";
        string template = TranslatorManager.instance.get_translated_text_by_code(code);

        string content = BdUtils.replace_template_variables(template, template_variable_dc);
        BdUtils.log(content);

        BdTools.show_message_box(content: content, destroy_time: 5);

        // BdUtils.log(" --- translate `嘎嘎`:", TranslatorManager.instance.translate_input_text_string("嘎嘎"));

        string old_text = "昵称: {{name}}, 等级: {{level}}";
        BdUtils.log(" --- translate --- ", old_text, "-->", TranslatorManager.instance.translate_input_text_string(old_text));
    }

    // Start is called before the first frame update
    void Start()
    {
        var translate_text_obj = BdTools.get_game_object_by_path("/Canvas/btn_translate_text_3");
        var translate_text_comp = BdTools.get_component_in_obj_self_or_children<TranslateText>(translate_text_obj);

        translate_text_comp.add_template_pretreat(my_replace_template_pretreat);
    }

    public string my_replace_template_pretreat(string template)
    {
        Dictionary<string, object> template_variable_dc = new Dictionary<string, object>();

        string name = TranslatorManager.instance.is_cn ? "哈哈" : "haha";
        template_variable_dc.Add("name", name);
        template_variable_dc.Add("level", 4);

        string res = BdUtils.replace_template_variables(template, template_variable_dc);
        return res;
    }

    // Update is called once per frame
    void Update()
    {

    }
}
